package com.freewater.cargotracker.infrastructure.persistence.mybatis.converter;

import com.freewater.cargotracker.domain.model.customer.Customer;
import com.freewater.cargotracker.domain.model.customer.CustomerNo;
import com.freewater.cargotracker.infrastructure.persistence.mybatis.dbobject.CustomerPO;

public class CustomerConverter {

    public static CustomerPO serialize(Customer customer) {
        if (customer == null) {
            return null;
        }
        CustomerPO customerPO = new CustomerPO();
        customerPO.setId(customer.getId());
        customerPO.setCustomerNo(customer.getCustomerID().getIdString());
        customerPO.setName(customer.getName());
        return customerPO;
    }

    public static Customer deserialize(CustomerPO customerPO) {
        if (customerPO == null) {
            return null;
        }
        final CustomerNo customerNo = new CustomerNo(customerPO.getCustomerNo());
        Customer customer = new Customer(customerNo, customerPO.getName());
        customer.setId(customerPO.getId());
        return customer;
    }
}
